package com.vip8.recorder.service.config;

import com.vip8.recorder.service.interceptor.LoginCheckInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    // 加自定义拦截器JwtInterceptor，设置拦截规则
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginCheckInterceptor()).addPathPatterns("/**").excludePathPatterns("/tiger/user/login"
//                ,"/user/login"
//                ,"/user/generateCode"
//                ,"/user/loginByCode"
//                ,"/recorder/getOssToken"
//                ,"/recorder/uploadVideo"
//                ,"/recorder/markVideo"
//        );
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") // 所有接口
                .allowCredentials(true) // 是否发送 Cookie
                .allowedOriginPatterns("*") // 支持域
                .allowedMethods(new String[]{"GET", "POST"}) // 支持方法
                .allowedHeaders("*")
                .exposedHeaders("*");
    }

    @Bean
    RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public LoginCheckInterceptor loginCheckInterceptor(){
        return new LoginCheckInterceptor();
    }
}
